<template>
  <div class="search-form">
    <a-form layout="inline">
      <a-form-item label="奖品名称">
        <a-input v-model:value="searchForm.name" placeholder="请输入奖品名称" allowClear />
      </a-form-item>
      <a-form-item label="奖品标签">
        <a-select
          v-model:value="searchForm.subTitle"
          placeholder="请选择奖品标签"
          allowClear
          style="width: 160px"
        >
          <a-select-option v-for="(item, key) in SubTypeEnum" :key="key" :value="key">
            {{ item.value }}
          </a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item>
        <a-space>
          <a-button type="primary" @click="handleSearch">搜索</a-button>
          <a-button @click="handleReset">重置</a-button>
        </a-space>
      </a-form-item>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { SubTypeEnum } from '@/utils/enumeration'

interface SearchForm {
  name: string
  subTitle: string
}

const searchForm = ref<SearchForm>({
  name: '',
  subTitle: '',
})

const emit = defineEmits<{
  (e: 'search', values: SearchForm): void
  (e: 'reset'): void
}>()

const handleSearch = () => {
  emit('search', searchForm.value)
}

const handleReset = () => {
  searchForm.value = {
    name: '',
    subTitle: '',
  }
  emit('reset')
}
</script>

<style lang="stylus" scoped>

.search-form {
  margin-bottom: 24px;
  padding: 10px;
  background: #fff;
  border-radius: 2px;
}
</style>
